home *** CD-ROM | disk | FTP | other *** search
/ Network Supervisor's Toolkit / Network Supervisor's Toolkit.iso / tools / mdxdos23 / mdxput.c < prev    next >
C/C++ Source or Header  |  1996-07-10  |  7KB  |  304 lines

  1. #include    "multix.h"
  2. #include    <stdio.h>
  3. #include    <stdlib.h>
  4. #include    <string.h>
  5. #include    <time.h>
  6.  
  7.  
  8. #include    "appl.h"
  9. TMdxProcId        MyId;
  10. Int8            SourceFile[25];
  11. Int8            TargetFile[25];
  12. Int8            ServerName[25];
  13. TFileTransferInfo    FtpFileInfo;
  14. TMdxMsg         *FtpMsg;
  15.  
  16. void    ApplDataReplyReceived(
  17. TMdxEvent    *Event
  18. )
  19. {
  20.     TMdxSRMsgInfo    *MsgInfo;
  21.     TFileTransferInfo    FileInfo;
  22.     Int8            Buf[300];
  23.  
  24.     /*
  25.     "Event->Data"    holds the information abount the new message.
  26.     */
  27.  
  28.     MsgInfo =    (TMdxSRMsgInfo    *)Event->Data;
  29.  
  30.     /*    First    thing is to check MsgCode of the new message    */
  31.  
  32.     switch(MsgInfo->Received.MsgCode)
  33.     {
  34.         case    ApplPutFileMsgCode    :
  35.         {
  36.             MdxMsgRead(MsgInfo->Sent.Msg,(UInt8Ptr)&FileInfo,sizeof(FileInfo));
  37.             printf("Copy File %s To (%s):%s  Completed Successfuly\n",
  38.             FileInfo.SrcFileName,
  39.             ServerName,
  40.             FileInfo.TgtFileName);
  41.             MdxMsgRead(MsgInfo->Received.Msg,Buf,sizeof(Buf)-1);
  42.             printf("\n\n\nServer Reply Is : %s\n",Buf);
  43.             ApplShutdown    =    True;
  44.         }
  45.         break;
  46.         default                     :    break;
  47.     }
  48. }
  49.  
  50.  
  51. TResult SetFtpMsg(
  52. Int8Ptr    Source,
  53. Int8Ptr Target
  54. )
  55. {
  56.     memset(&FtpFileInfo,0,sizeof(FtpFileInfo));
  57.  
  58.     strcpy(FtpFileInfo.SrcFileName,Source);
  59.     strcpy(FtpFileInfo.TgtFileName,Target);
  60.     FtpFileInfo.ReplaceFile =    True;
  61.  
  62.     FtpMsg =    MdxMsgNewFile(    FtpFileInfo.SrcFileName,
  63.                                 (UInt8Ptr)&FtpFileInfo,sizeof(FtpFileInfo));
  64.  
  65.     if ( (FtpMsg) == (void *)0 )    return(Failure);
  66.     return(Success);
  67.  
  68. }
  69.  
  70. void    ApplSendPutFileReq(
  71. TMdxProcId    ProcId
  72. )
  73. {
  74.     TMdxError    Result;
  75.     Result    =    MdxSendMsg( ProcId,
  76.                                 FtpMsg,                    /*    Msg                */
  77.                                 ApplPutFileMsgCode,    /*    Msg Code        */
  78.                                 10,                        /*    Lowest Priority    */
  79.                                 MdxSendReliable,        /*    Send Attributes    */
  80.                                                         /*    Success/Failure    */
  81.                                                         /*    Report            */
  82.                                 0,                        /*    No ReqSeq        */
  83.                                 12000                    /*    10 Secs Timeout    */
  84.                                                         /*    for the other side*/
  85.                                                         /*    to confirm message*/
  86.                                 );
  87.     printf("(%ld) Sending File - %s\n",
  88.             MdxGetCurrTimerValue(),FtpFileInfo.SrcFileName);
  89.     if (    Result    !=    MdErrNoError    )
  90.     {
  91.         printf("(%ld) Send Failed With Error - %d\n",
  92.                 MdxGetCurrTimerValue(),Result);
  93.  
  94.     }
  95. }
  96.  
  97.  
  98. void    ApplCallCompleted(
  99. TMdxEvent    *Event
  100. )
  101. {
  102.     printf("(%ld) Call Completed to Process (%ld)\n",
  103.             MdxGetCurrTimerValue(),Event->ProcId);
  104. }
  105.  
  106.  
  107. void    ApplInitReceived(void)
  108. {
  109.     TMdxProcessParams    ProcessParams;
  110.     TMdxLinkParams    LinkParams;
  111.  
  112.     /*
  113.     You may choose to use onw or more links of the types specified.
  114.     Un comment the relevent "MdxOpenLink()".
  115.  
  116.     You may change the parameters for the links.
  117.     */
  118.  
  119.  
  120.     memset(&LinkParams,0,sizeof(LinkParams));
  121.     strcpy(LinkParams.LinkName.Byte,"com2");
  122.     LinkParams.LinkType                =    MdxLinkTypeAsyncLocal;
  123.     LinkParams.ConnectMode            =    MdxConnectModeCall;
  124.     LinkParams.ConnectTimeout        =    0x7fffffff;
  125.     LinkParams.MaxConnectRetries    =    -1;
  126.     LinkParams.ConnectRetriesDelay    =    200;
  127.     LinkParams.LinkBaud             =    19200;
  128.     LinkParams.UseDlcFraming        =    True;
  129.     LinkParams.ImAliveInterval        =    400l;
  130.     LinkParams.MaxPollRetries        =    2;
  131.     LinkParams.L1MaxSendSize        =    256;
  132.     /*
  133.     MdxOpenLink(&LinkParams);
  134.     */
  135.     memset(&LinkParams,0,sizeof(LinkParams));
  136.     strcpy(LinkParams.LinkName.Byte,"MdxFs");
  137.     LinkParams.LinkType                =    MdxLinkTypeSpxIpx;
  138.     LinkParams.ConnectMode            =    MdxConnectModeCall;
  139.     LinkParams.ConnectTimeout        =    1000;
  140.     LinkParams.MaxConnectRetries    =    -1;
  141.     LinkParams.ConnectRetriesDelay    =    200;
  142.     LinkParams.UseDlcFraming        =    True;
  143.     LinkParams.MaxPollRetries        =    10;
  144.     LinkParams.L1MaxSendSize        =    500;
  145.     /*
  146.     MdxOpenLink(&LinkParams);
  147.     */
  148.  
  149.     memset(&LinkParams,0,sizeof(LinkParams));
  150.     strcpy(LinkParams.LinkName.Byte,"MdxFs");
  151.     LinkParams.LinkType                =    MdxLinkTypeNetBios;
  152.     LinkParams.ConnectMode            =    MdxConnectModeCall;
  153.     LinkParams.ConnectTimeout        =    0x7fffffffl;
  154.     LinkParams.ConnectRetriesDelay    =    300l;
  155.     LinkParams.L1MaxSendSize        =    1024;
  156.     LinkParams.MaxConnectRetries    =    -1l;
  157.     /*
  158.     MdxOpenLink(&LinkParams);
  159.     */
  160.  
  161.  
  162.  
  163.  
  164.     memset(&ProcessParams,0,sizeof(ProcessParams));
  165.     ProcessParams.ProcId                    =    CallId;
  166.     ProcessParams.InactivityTimer            =    6000;
  167.     ProcessParams.ConnectRetriesInterval    =    200;
  168.     MdxConnectProcess(&ProcessParams);
  169.     printf("(%ld) Calling %ld\n",MdxGetCurrTimerValue(),ProcessParams.ProcId);
  170.     ApplSendPutFileReq(CallId);
  171. }
  172.  
  173.  
  174. void    ApplSendMsgCompleted(
  175. TMdxEvent    *Event
  176. )
  177. {
  178.     TMdxSRMsgInfo        *MsgInfo;
  179.     TFileTransferInfo    FileInfo;
  180.  
  181.     /*
  182.     "Event->Data"    holds the information abount the Message we sent.
  183.     */
  184.  
  185.     MsgInfo =    (TMdxSRMsgInfo    *)Event->Data;
  186.     switch(MsgInfo->Sent.MsgCode)
  187.     {
  188.         case    ApplPutFileMsgCode    :
  189.         {
  190.             MdxMsgRead(MsgInfo->Sent.Msg,(UInt8Ptr)&FileInfo,sizeof(FileInfo));
  191.             printf("Copy File %s To (%s):%s  ",
  192.                     FileInfo.SrcFileName,
  193.                     ServerName,
  194.                     FileInfo.TgtFileName);
  195.             if (    Event->Error    ==    MdErrNoError    )
  196.             {
  197.                 printf("Completed Successfuly\n");
  198.             } else
  199.             {
  200.                 printf("Failed : Error = %d\n",Event->Error);
  201.             }
  202.             ApplShutdown    =    True;
  203.         }
  204.         break;
  205.         default                     :    break;
  206.     }
  207. }
  208.  
  209.  
  210. void    cdecl    ApplEventHandler(
  211. TMdxEvent    *Event
  212. )
  213. {
  214.     switch(Event->Code)
  215.     {
  216.         case    MdxEvSendMsgCompleted        :
  217.         {
  218.             ApplSendMsgCompleted(Event);
  219.         }
  220.         break;
  221.         case    MdxEventApplInit                :
  222.         {
  223.             ApplInitReceived();
  224.         }
  225.         break;
  226.         case    MdxEvCallCompleted            :
  227.         case    MdxEvCallRejected            :
  228.         {
  229.             ApplCallCompleted(Event);
  230.         }
  231.         break;
  232.         case    MdxEvDataReplyReceived        :
  233.         {
  234.             ApplDataReplyReceived(Event);
  235.         }
  236.         break;
  237.         case    MdxStdInAvailable                :
  238.         {
  239.             ApplShutdown    =    True;
  240.         }
  241.         break;
  242.  
  243.         default                                 :    break;
  244.     }
  245. }
  246.  
  247.  
  248. Int cdecl    main(
  249. Int     Argc,
  250. Int8Ptr *Argv
  251. )
  252. {
  253.     TSIndex CallIndex;
  254.     MyId    =    99999999;
  255.  
  256.     if (    Argc    <    3    )
  257.     {
  258.         printf("Usage : mdxput SourceFile [TargetFile] <Server Id To Call>\n");
  259.         return(5);
  260.     }
  261.     strcpy(SourceFile,Argv[1]);
  262.     if (    Argc    >    3    )
  263.     {
  264.         strcpy(TargetFile,Argv[2]);
  265.         CallIndex    =    3;
  266.     } else
  267.     {
  268.         strcpy(TargetFile,SourceFile);
  269.         CallIndex    =    2;
  270.     }
  271.     if ( (getenv(Argv[CallIndex])) != (void *)0 )
  272.     {
  273.         CallId    =    atol(getenv(Argv[CallIndex]));
  274.         strcpy(ServerName,getenv(Argv[CallIndex]));
  275.     } else
  276.     {
  277.         CallId    =    atol(Argv[CallIndex]);
  278.         strcpy(ServerName,Argv[CallIndex]);
  279.     }
  280.  
  281.     if (    CallId    ==    0    )
  282.     {
  283.         printf("Invalid Value For Id To Call\n");
  284.         exit(0);
  285.     }
  286.  
  287.  
  288.     MultiXStart(MyId,"Mdx File Copy",0,ApplEventHandler);
  289.  
  290.     if (    SetFtpMsg(SourceFile,TargetFile)    !=    Success )
  291.     {
  292.         printf("Invalid File To Copy\n");
  293.         exit(0);
  294.  
  295.     }
  296.     printf("Type any key to stop the program...\n");
  297.  
  298.     while (    ApplShutdown    ==    False    )
  299.     {
  300.         MultiXWaitEvent();
  301.     }
  302.     return(0);
  303. }
  304.